﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRM.Entity;
using CRM.BLL;
using DP.Web.UI;
using DP.Common;

namespace CRM.Web.LogManage
{
    public partial class Modify : Common.PageBase
    {

        T_LOG_BLL bll = new T_LOG_BLL();
        protected override void OnInit(EventArgs e)
        {
            base.VerificationRight = false;
            base.OnInit(e);
            PageHelper.SetPrePageUrl(this.Page);
            PageHelper.SetGoBackUrl(this.Page, btnCancel);
            //PageHelper.SetPopCalender(this.Page, txtLOGINTIME);
            //PageHelper.SetPopCalender(this.Page, txtCREATETIME);

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlLOGTYPEIDBinding();


                pageDataInit();
            }
        }

        #region 页面初始化数据绑定

        /// <summary>
        ///	日志类型 下拉列表数据绑定
        /// </summary>
        /// <summary>
        ///	日志类型 下拉列表数据绑定
        /// </summary>
        private void ddlLOGTYPEIDBinding()
        {
            ddlLOGTYPEID.Items.Clear();
            EnumHelper.FillListControl(ddlLOGTYPEID, typeof(LogType));
            ddlLOGTYPEID.Items.Insert(0, new ListItem("", ""));
        }
















        #endregion

        private void pageDataInit()
        {
            string _logid = String.IsNullOrEmpty(Request.QueryString["LOGID"]) ? "" : Request.QueryString["LOGID"].Trim();

            if (!String.IsNullOrEmpty(_logid))
            {
                T_LOG_Entity entity = bll.GetEntity("LOGID", _logid);

                PageHelper.SetControlValue<T_LOG_Entity>(this.Page, entity);
                lblTitle.Text = "系统日志查看";
            }

            txtLOGID.ReadOnly = true;

        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            string _logid = String.IsNullOrEmpty(Request.QueryString["LOGID"]) ? "" : Request.QueryString["LOGID"].Trim();


            T_LOG_Entity entity = bll.GetEntity("LOGID", _logid);

            if (entity != null)
            {
                PageHelper.GetControlValue<T_LOG_Entity>(this.Page, ref entity);

                long rel = bll.Update(entity);
                if (rel > 0)
                {
                    PageHelper.ShowMessage(this.Page, "修改成功！", "list.aspx");
                }
                else
                {
                    PageHelper.ShowMessage(this.Page, "修改失败！");
                }
            }
            else
            {
                entity = new T_LOG_Entity();

                PageHelper.GetControlValue<T_LOG_Entity>(this.Page, ref entity);

                long rel = bll.Insert(entity);
                if (rel > 0)
                {
                    PageHelper.ShowMessage(this.Page, "添加成功！", "list.aspx");
                }
                else
                {
                    PageHelper.ShowMessage(this.Page, "添加失改！");
                }

            }
        }
    }
}
